
Page({

  
  data: {
    collectList:[],
  },

  
  onLoad: function (options) {
    let app = getApp()
    console.log(app.globalData.userInfo.openid)
    wx.request({
      url: app.globalData.url + '/home/listcollect',
      data:{
        openId:app.globalData.userInfo.openid,
      },
      success: result => {
        let collectList = result.data.data
        
        for(let i = 0; i < collectList.length; ++i){
          if(collectList[i].category == "daily"){
            let contentArray = collectList[i].content.split("#")
            collectList[i]["question"] = contentArray[0]
            collectList[i]["answer"] = contentArray[1]
          }else{
            let contentArray = collectList[i].content.split("#")
            collectList[i]["question"] = contentArray[0]
            collectList[i]["tag"] = contentArray[1]
          }
        }
        
        this.setData({
          collectList:collectList
        })
      }
    })
  },
  goToSearch:function () {
    wx.navigateTo({
      url: '/pages/search/search?source=collect',
    })
  },
  
  onReady: function () {

  },
  onShow: function () {

  },
  goToDetail:function(event){
    let questionId = event.currentTarget.dataset.questionId
    let title = event.currentTarget.dataset.tag
    let app = getApp()
    wx.request({
      url: app.globalData.url + '/question/getq',
      data:{
        questionId:questionId,
        openId:app.globalData.userInfo.openid,
      },
      header: {
        'content-type': 'application/json' 
      },
      success: result => {
        let question = result.data.data
        question["title"] = title
        app.globalData.errorSource = question
        wx.navigateTo({
          url: '/pages/collection/collection?source=collect&bookId='+question.bookId,
        })
      }
    })

    
  },
  onHide: function () {

  },
  onUnload: function () {

  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {

  },
  onShareAppMessage: function () {

  }
})